﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aribaccio;
using CommunityToolkit.Mvvm.ComponentModel;

namespace BDPAutodetect.Client
{
    public partial class PagerViewModel<TModel, TParent> : BaseViewModel<TParent>
        where TModel : class, new()
        where TParent : class
    {
        /// <summary>
        /// 所有分页数据集合
        /// </summary>
        [ObservableProperty]
        protected PagerList<TModel>? pagerData;
        /// <summary>
        /// 当前分页数据集合
        /// </summary>
        [ObservableProperty]
        protected ObservableCollection<TModel>? pagerCurrentItems;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="argPageSize"></param>
        public PagerViewModel(int argPageSize) : base()
        {
            this.PagerData = new PagerList<TModel>(argPageSize);
        }

        /// <summary>
        /// 初始化创建集合
        /// </summary>
        protected void InitCreateItems(ObservableCollection<TModel> argItems)
        {
            if (this.PagerData == null) { this.PagerData = new PagerList<TModel>(); }
            if (this.PagerData != null)
            {
                this.PagerCurrentItems?.Clear();
                this.PagerData.ItemsSource = new ObservableCollection<TModel>(argItems);
                this.PagerData.PagerUpdated += items =>
                {
                    this.PagerCurrentItems = new ObservableCollection<TModel>(items);
                };
                this.PagerData.CurPageIndex = 1;
            }
        }

    }
}
